// mch//m/buy-mch/buy-mch.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
       
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (e) {
        getApp().page.onLoad(this, e);
        var n = this;
        getApp().core.showLoading({
            title: "加载中"
        }), getApp().request({
            url: getApp().api.mch.buy_mch,
            success: function(e) {
                var t = e.data; console.log(t);
                0 == t.balance ? getApp().core.showModal({
                    title: "提示",
                    content: "充值功能未开启，请联系管理员！",
                    showCancel: !1,
                    success: function(e) {
                        e.confirm && getApp().core.navigateBack({
                            delta: 1
                        });
                    }
                }) : n.setData(e.data);
            },
            complete: function(e) {
                getApp().core.hideLoading();
            }
        })
    },
    pay: function(e) {
        var t = this, a = t.data.balance;
        getApp().request({
            url: getApp().api.mch.pay_mch,
            data: {
                balance: a
            },
            success: function(e) {
                console.log(e), 0 == e.code && getApp().core.showModal({
                    title: '提示',
                    content: '购买成功',
                    showCancel: !1,
                    success: function(e) {
                        e.confirm && getApp().core.redirectTo({
                            url: "/mch/m/myshop/myshop"
                        })
                    }
                }), 2 == e.code && getApp().core.showModal({
                    title: '提示',
                    content: e.msg,
                    showCancel: !1,
                    success: function(e) {
                        e.confirm && getApp().core.navigateTo({
                            url: "/pages/recharge/recharge"
                        })
                    }
                }), 1 == e.code && getApp().core.showToast({
                    title: e.msg
                });
            }
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})